package com.ordering.login.action;

import java.sql.SQLException;

import com.ordering.entity.UserInfo;
import com.ordering.login.dao.LoginDao;


public class LoginAction extends BaseAction {
    
    //输入
    private String username;
    private String password;
    private String errorMsg;
//  private String imageCode;
    
    public String execute() {
//      //追加对验证码的校验
//      String code = (String)
//          session.get("imageCode");
//      if(imageCode != null && imageCode.equalsIgnoreCase(code)){
//          //输入的验证码和图片中一致，代码向下执行，验证用户名密码
//          
//      } else {
//          //不一致，则返回fail
//          errorMsg = "验证码输入有误！";
//          return "fail";
//      }
        LoginDao dao = new LoginDao();
        UserInfo user = null;
        user = dao.findUser(username, password);
        
        if(user == null) {
            errorMsg = "账号或密码错误！";
            return "fail";
        } else {
            session.put("user", user);
            return "success";
        }
    }
    
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
    
}
